package com.itheima.testController;


import com.itheima.bean.Result;

import com.itheima.vo.question;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 试题表 前端控制器
 * </p>
 *
 * @author itheima
 * @since 2021-03-28
 */
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * @description:查题目
     * @author: Java
     * @date: 2021/3/28 13:14
     * @param: queryPageBean
     * @return: com.itheima.bean.Result
     */
/*    @PostMapping("show")
    public Result show() {
        try {
            // new几个question
            int i = 0;
            question question1 = createQuestion(i++);
            question question2 = createQuestion(i++);
            question question3 = createQuestion(i++);
            question question4 = createQuestion(i++);
            question question5 = createQuestion(i);
            question question6 = createQuestion(i);
            question question7 = createQuestion(i);
            question question8 = createQuestion(i);
            question question9 = createQuestion(i);
            question question10 = createQuestion(i);
            question question11 = createQuestion(i);
            question question12 = createQuestion(i);
            question question13 = createQuestion(i);
            question question14 = createQuestion(i);
            question question15 = createQuestion(i);

            // 加题目名字
            question1.setQuestionstem("头痛");
            question2.setQuestionstem("神经过敏，心中不踏实");
            question3.setQuestionstem("测试1111");
            question4.setQuestionstem("测试2222");
            question5.setQuestionstem("测试3333");
            question6.setQuestionstem("测试4444");
            question7.setQuestionstem("测试5555");
            question8.setQuestionstem("测试6666");
            question9.setQuestionstem("测试7777");
            question10.setQuestionstem("测试8888");
            question11.setQuestionstem("测试9999");
            question12.setQuestionstem("测试1010");
            question13.setQuestionstem("测试1111");
            question14.setQuestionstem("测试1212");
            question15.setQuestionstem("测试1313");

            // new一个questions集合
            ArrayList<question> questions = new ArrayList<>();
            // 存几个
            questions.add(question1);
            questions.add(question2);
            questions.add(question3);
            questions.add(question4);
            questions.add(question5);
            questions.add(question6);
            questions.add(question7);
            questions.add(question8);
            questions.add(question9);
            questions.add(question10);
            questions.add(question11);
            questions.add(question12);
            questions.add(question13);
            questions.add(question14);
            questions.add(question15);


            //new一个subjectVo
            subjectVo subjectVo = new subjectVo();
            subjectVo.setInstId(1);
            subjectVo.setQuestions(questions);
            return new Result(true, "查询题目成功", subjectVo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "失败");
        }

    }*/

    private question createQuestion(int i) {
        List<String> Choice = new ArrayList<>();
        question question = new question();
        Choice.add("没有");
        Choice.add("很轻");
        Choice.add("中等");
        Choice.add("偏重");
        Choice.add("严重");
        question.setChoice(Choice);
        question.setQuestionType(2);
        question.setAnswer(i);

        return question;
    }


    @RequestMapping("submit")
    public Result submit(int id, @RequestBody ArrayList<Integer> answer) {
        try {
            System.out.println("id = " + id);
            System.out.println("answerVo= " + answer);
            return new Result(true, "提交成功", answer);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "提交失败");
        }

    }

}
